# Foreign Aid and State Legitimacy in Africa: Cross-National and Sub-National 
# Evidence from Surveys, Survey Experiments, and Behavioral Games

# Table A.10: Descriptive statistics for cross-country analysis

# Load Data --------------------------------------------------------------------
data <- readRDS(file.path(data_file_path, "afro_china_data.Rds"))

# Subset Data ------------------------------------------------------------------
data <- data %>%
  filter(noyeardata_near_china.pl10.bin == 0,
         implementing_near_china.pl10.bin == 0,
         noyeardata_near_usaid.bin == 0,
         implementing_near_usaid.bin == 0,
         iso %in% iso_usaid)

# Make Table -------------------------------------------------------------------
sink(file.path(tables_file_path, "table_a10.tex"))

cat("\\begin{tabular}{lccccccc} ")
cat(" \\hline ")
cat(" Variable  & Mean & SD & Min & Max & First Round & Last Round \\\\")
cat("   &  &  &  & & Available & Available \\\\")
cat(" \\hline ")

for(var in c("trust_index", 
             "democ_high_qual",
             "refuse_pay_tax",
             "gov_right_tax",
             "easy_avoid_tax")){
  
  if(var == "trust_index"){
    cat("Trust in Gov [Index]", " & ")
  }
  
  if(var == "democ_high_qual"){
    cat("Believes Democ is High Qual", " & ")
  }
  
  if(var == "refuse_pay_tax"){
    cat("Has Refused to Pay Tax", " & ")
  }
  
  if(var == "gov_right_tax"){
    cat("Believes Govt Right to Tax", " & ")
  }
  
  if(var == "easy_avoid_tax"){
    cat("Believes Easy Avoid Tax", " & ")
  }
  
  cat(round(mean(data[[var]], na.rm=T), 2), " & ")
  cat(round(sd(data[[var]], na.rm=T), 2), " & ")
  cat(round(min(data[[var]], na.rm=T), 2), " & ")
  cat(round(max(data[[var]], na.rm=T), 2), " & ")
  cat(min(data$afro.round[!is.na(data[[var]])]), " & ")
  cat(max(data$afro.round[!is.na(data[[var]])]), " \\\\ ")
  
}

cat(" \\hline ")
cat(" \\end{tabular} ")

sink()


